﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace binary
{
    public partial class ExecProcedure : Form
    {
        private ConfigSingle config;
        private string query = "";
        private Thread executeThread;
        private delegate void CloseDelegate();

        public ExecProcedure(ConfigSingle cfg, string query)
        {
            this.query = query;
            this.config = cfg;
            InitializeComponent();
        }

        private void ExecProcedure_Load(object sender, EventArgs e)
        {
            executeThread = new Thread(new ThreadStart(execute));
            executeThread.Start();
        }

        private void execute()
        {
            mySqlConnection c = new mySqlConnection(config);
            c.QueryNoResult(String.Format("exec {0}",query));
            c.Disconnect();
            Invoke(new CloseDelegate(CloseForm));
        }

        private void CloseForm()
        {
            while (executeThread.ThreadState == ThreadState.Running)
                Thread.Sleep(100);
            this.Close();
        }
    }
}
